package com.hc.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hc.bean.RoleBean;
import com.hc.service.SetDataService;
import com.hc.serviceImpl.SetDataServiceImpl;

public class SetDataServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	
	String types = req.getParameter("types");  
	
	if("downFile".equals(types)){
		setdownFileData(req, resp);
	}else if("web".equals(types)){
		
		setWebData(req, resp);
	}
	
	
	
}

private void setWebData(HttpServletRequest req, HttpServletResponse resp) {
	
	
	HttpSession session = req.getSession();  
	
	RoleBean bean = (RoleBean) session.getAttribute("roleBean");
	
	if(bean!=null){
		Map<String,String[]> map = req.getParameterMap();
		SetDataService service = new SetDataServiceImpl();
		service.setWebData( map,bean);
	}

}

private void setdownFileData(HttpServletRequest req, HttpServletResponse resp) {
	
	HttpSession session = req.getSession();  
	
	RoleBean bean = (RoleBean) session.getAttribute("roleBean");
	
	if(bean!=null){
	Map<String,String[]> map = req.getParameterMap();
	SetDataService service = new SetDataServiceImpl();
	service.setdownFileData(map,bean);
	}
}

@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
		doPost(req, resp);
	}
}
